package com.irdstudio.tdp.executor.core.dao;

import com.irdstudio.tdp.executor.core.dao.domain.SUser;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

/**
 * 用户管理类-[表名: 用户管理(s_user)]
 * 通过JDBC实现基本的数据表操作(CRUD) 
 * @author 代码自动生成
 * @version 1.0
 * @date 2020-11-13
 */
public class SUserDao {

	/* 连接对象 */
	Connection conn = null;	

	public SUserDao(Connection conn){
		this.conn = conn;
	}


    /**
	* 新增一行
	* @return int
	*/
    public int insertSUser(SUser sUser) throws SQLException {

        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            ps = conn.prepareStatement("insert into s_user ( "
                + "actorno,enname,actorname,nickname,state,password,startdate,passwvalda,firedate,birthday,telnum,idcardno,allowopersys,lastlogdat,creater,creattime,usermail,wrongpinnum,isadmin,memo,ipmask,orderno,question,answer,orgid,depno,session_id,rank,parentactorno,device_no,menu_config,is_priority_show,if_together_wf,op_model,mob_num"
                + ") values ("+ "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?" +")"
                );
            ps.setObject(1, sUser.getActorno());
            ps.setObject(2, sUser.getEnname());
            ps.setObject(3, sUser.getActorname());
            ps.setObject(4, sUser.getNickname());
            ps.setObject(5, sUser.getState());
            ps.setObject(6, sUser.getPassword());
            ps.setObject(7, sUser.getStartdate());
            ps.setObject(8, sUser.getPasswvalda());
            ps.setObject(9, sUser.getFiredate());
            ps.setObject(10, sUser.getBirthday());
            ps.setObject(11, sUser.getTelnum());
            ps.setObject(12, sUser.getIdcardno());
            ps.setObject(13, sUser.getAllowopersys());
            ps.setObject(14, sUser.getLastlogdat());
            ps.setObject(15, sUser.getCreater());
            ps.setObject(16, sUser.getCreattime());
            ps.setObject(17, sUser.getUsermail());
            ps.setObject(18, sUser.getWrongpinnum());
            ps.setObject(19, sUser.getIsadmin());
            ps.setObject(20, sUser.getMemo());
            ps.setObject(21, sUser.getIpmask());
            ps.setObject(22, sUser.getOrderno());
            ps.setObject(23, sUser.getQuestion());
            ps.setObject(24, sUser.getAnswer());
            ps.setObject(25, sUser.getOrgid());
            ps.setObject(26, sUser.getDepno());
            ps.setObject(27, sUser.getSessionId());
            ps.setObject(28, sUser.getRank());
            ps.setObject(29, sUser.getParentactorno());
            ps.setObject(30, sUser.getDeviceNo());
            ps.setObject(31, sUser.getMenuConfig());
            ps.setObject(32, sUser.getIsPriorityShow());
            ps.setObject(33, sUser.getIfTogetherWf());
            ps.setObject(34, sUser.getOpModel());
            ps.setObject(35, sUser.getMobNum());
            return ps.executeUpdate();
        } catch (SQLException e) {
            throw new SQLException("insert SUser is Wrong!" + e.getMessage());
        } finally {
            close(rs, null, ps);
        }
	}

    /**
	* 根据主键删除一行记录
	* @return int
	*/
    public int deleteByPk(SUser sUser) throws SQLException {

        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            ps = conn.prepareStatement("delete from s_user where 1=1"
                + " AND actorno = ? "
                );
            ps.setObject(1, sUser.getActorno());
            return ps.executeUpdate();
        } catch (SQLException e) {
            throw new SQLException("delete SUser is Wrong!" + e.getMessage());
        } finally {
            close(rs, null, ps);
        }
	}

    /**
	* 根据主键更新一行记录
	* @return int
	*/
    public int updateByPk(SUser sUser) throws SQLException {

        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            ps = conn.prepareStatement("update s_user set "
                + " actorno = ? ,"
                + " enname = ? ,"
                + " actorname = ? ,"
                + " nickname = ? ,"
                + " state = ? ,"
                + " password = ? ,"
                + " startdate = ? ,"
                + " passwvalda = ? ,"
                + " firedate = ? ,"
                + " birthday = ? ,"
                + " telnum = ? ,"
                + " idcardno = ? ,"
                + " allowopersys = ? ,"
                + " lastlogdat = ? ,"
                + " creater = ? ,"
                + " creattime = ? ,"
                + " usermail = ? ,"
                + " wrongpinnum = ? ,"
                + " isadmin = ? ,"
                + " memo = ? ,"
                + " ipmask = ? ,"
                + " orderno = ? ,"
                + " question = ? ,"
                + " answer = ? ,"
                + " orgid = ? ,"
                + " depno = ? ,"
                + " session_id = ? ,"
                + " rank = ? ,"
                + " parentactorno = ? ,"
                + " device_no = ? ,"
                + " menu_config = ? ,"
                + " is_priority_show = ? ,"
                + " if_together_wf = ? ,"
                + " op_model = ? ,"
                + " mob_num = ? "
                + " where 1=1"
                + " AND actorno = ? "
                );
            ps.setObject(1, sUser.getActorno());
            ps.setObject(2, sUser.getEnname());
            ps.setObject(3, sUser.getActorname());
            ps.setObject(4, sUser.getNickname());
            ps.setObject(5, sUser.getState());
            ps.setObject(6, sUser.getPassword());
            ps.setObject(7, sUser.getStartdate());
            ps.setObject(8, sUser.getPasswvalda());
            ps.setObject(9, sUser.getFiredate());
            ps.setObject(10, sUser.getBirthday());
            ps.setObject(11, sUser.getTelnum());
            ps.setObject(12, sUser.getIdcardno());
            ps.setObject(13, sUser.getAllowopersys());
            ps.setObject(14, sUser.getLastlogdat());
            ps.setObject(15, sUser.getCreater());
            ps.setObject(16, sUser.getCreattime());
            ps.setObject(17, sUser.getUsermail());
            ps.setObject(18, sUser.getWrongpinnum());
            ps.setObject(19, sUser.getIsadmin());
            ps.setObject(20, sUser.getMemo());
            ps.setObject(21, sUser.getIpmask());
            ps.setObject(22, sUser.getOrderno());
            ps.setObject(23, sUser.getQuestion());
            ps.setObject(24, sUser.getAnswer());
            ps.setObject(25, sUser.getOrgid());
            ps.setObject(26, sUser.getDepno());
            ps.setObject(27, sUser.getSessionId());
            ps.setObject(28, sUser.getRank());
            ps.setObject(29, sUser.getParentactorno());
            ps.setObject(30, sUser.getDeviceNo());
            ps.setObject(31, sUser.getMenuConfig());
            ps.setObject(32, sUser.getIsPriorityShow());
            ps.setObject(33, sUser.getIfTogetherWf());
            ps.setObject(34, sUser.getOpModel());
            ps.setObject(35, sUser.getMobNum());
            ps.setObject(36, sUser.getActorno());
            return ps.executeUpdate();
        } catch (SQLException e) {
            throw new SQLException("update SUser is Wrong!" + e.getMessage());
        } finally {
            close(rs, null, ps);
        }

	}

    /**
	* 根据主键查询一行记录
	* @return int
	*/
    public SUser queryByPk(SUser sUser) throws SQLException {
        PreparedStatement ps = null;
        ResultSet rs = null;
        SUser result = null;
        try {
            ps = conn.prepareStatement("select actorno,enname,actorname,nickname,state,password,startdate,passwvalda,firedate,birthday,telnum,idcardno,allowopersys,lastlogdat,creater,creattime,usermail,wrongpinnum,isadmin,memo,ipmask,orderno,question,answer,orgid,depno,session_id,rank,parentactorno,device_no,menu_config,is_priority_show,if_together_wf,op_model,mob_numfrom s_user where 1=1 "
                + " AND actorno = ? "
                );
            ps.setObject(1, sUser.getActorno());
            rs = ps.executeQuery();
            if (rs.next()) {
				result = new SUser();
				result.setActorno(rs.getString("actorno"));
				result.setEnname(rs.getString("enname"));
				result.setActorname(rs.getString("actorname"));
				result.setNickname(rs.getString("nickname"));
				result.setState(rs.getString("state"));
				result.setPassword(rs.getString("password"));
				result.setStartdate(rs.getString("startdate"));
				result.setPasswvalda(rs.getString("passwvalda"));
				result.setFiredate(rs.getString("firedate"));
				result.setBirthday(rs.getString("birthday"));
				result.setTelnum(rs.getString("telnum"));
				result.setIdcardno(rs.getString("idcardno"));
				result.setAllowopersys(rs.getString("allowopersys"));
				result.setLastlogdat(rs.getString("lastlogdat"));
				result.setCreater(rs.getString("creater"));
				result.setCreattime(rs.getString("creattime"));
				result.setUsermail(rs.getString("usermail"));
				result.setWrongpinnum(rs.getBigDecimal("wrongpinnum"));
				result.setIsadmin(rs.getString("isadmin"));
				result.setMemo(rs.getString("memo"));
				result.setIpmask(rs.getString("ipmask"));
				result.setOrderno(rs.getBigDecimal("orderno"));
				result.setQuestion(rs.getString("question"));
				result.setAnswer(rs.getString("answer"));
				result.setOrgid(rs.getString("orgid"));
				result.setDepno(rs.getString("depno"));
				result.setSessionId(rs.getString("session_id"));
				result.setRank(rs.getString("rank"));
				result.setParentactorno(rs.getString("parentactorno"));
				result.setDeviceNo(rs.getString("device_no"));
				result.setIsPriorityShow(rs.getString("is_priority_show"));
				result.setIfTogetherWf(rs.getString("if_together_wf"));
				result.setOpModel(rs.getString("op_model"));
				result.setMobNum(rs.getString("mob_num"));
			}
        } catch (SQLException e) {
            throw new SQLException("update SUser is Wrong!" + e.getMessage());
        } finally {
            close(rs, null, ps);
        }
        return result;
	}

    /**
	* 根据 sUser 参数列表查询 不分页
	* @return int
	*/
    public List<SUser> queryAll(SUser sUser) throws SQLException {
        PreparedStatement ps = null;
        ResultSet rs = null;
        List<SUser> result = new ArrayList<>();
        try {
            String sql = "select actorno,enname,actorname,nickname,state,password,startdate,passwvalda,firedate,birthday,telnum,idcardno,allowopersys,lastlogdat,creater,creattime,usermail,wrongpinnum,isadmin,memo,ipmask,orderno,question,answer,orgid,depno,session_id,rank,parentactorno,device_no,menu_config,is_priority_show,if_together_wf,op_model,mob_numfrom s_user where 1=1 ";
                if (sUser.getActorno() != null) {
                    sql = sql + " AND actorno =  '" + sUser.getActorno() + "'";
                }
                if (sUser.getEnname() != null) {
                    sql = sql + " AND enname =  '" + sUser.getEnname() + "'";
                }
                if (sUser.getActorname() != null) {
                    sql = sql + " AND actorname =  '" + sUser.getActorname() + "'";
                }
                if (sUser.getNickname() != null) {
                    sql = sql + " AND nickname =  '" + sUser.getNickname() + "'";
                }
                if (sUser.getState() != null) {
                    sql = sql + " AND state =  '" + sUser.getState() + "'";
                }
                if (sUser.getPassword() != null) {
                    sql = sql + " AND password =  '" + sUser.getPassword() + "'";
                }
                if (sUser.getStartdate() != null) {
                    sql = sql + " AND startdate =  '" + sUser.getStartdate() + "'";
                }
                if (sUser.getPasswvalda() != null) {
                    sql = sql + " AND passwvalda =  '" + sUser.getPasswvalda() + "'";
                }
                if (sUser.getFiredate() != null) {
                    sql = sql + " AND firedate =  '" + sUser.getFiredate() + "'";
                }
                if (sUser.getBirthday() != null) {
                    sql = sql + " AND birthday =  '" + sUser.getBirthday() + "'";
                }
                if (sUser.getTelnum() != null) {
                    sql = sql + " AND telnum =  '" + sUser.getTelnum() + "'";
                }
                if (sUser.getIdcardno() != null) {
                    sql = sql + " AND idcardno =  '" + sUser.getIdcardno() + "'";
                }
                if (sUser.getAllowopersys() != null) {
                    sql = sql + " AND allowopersys =  '" + sUser.getAllowopersys() + "'";
                }
                if (sUser.getLastlogdat() != null) {
                    sql = sql + " AND lastlogdat =  '" + sUser.getLastlogdat() + "'";
                }
                if (sUser.getCreater() != null) {
                    sql = sql + " AND creater =  '" + sUser.getCreater() + "'";
                }
                if (sUser.getCreattime() != null) {
                    sql = sql + " AND creattime =  '" + sUser.getCreattime() + "'";
                }
                if (sUser.getUsermail() != null) {
                    sql = sql + " AND usermail =  '" + sUser.getUsermail() + "'";
                }
                if (sUser.getWrongpinnum() != null) {
                    sql = sql + " AND wrongpinnum =  '" + sUser.getWrongpinnum() + "'";
                }
                if (sUser.getIsadmin() != null) {
                    sql = sql + " AND isadmin =  '" + sUser.getIsadmin() + "'";
                }
                if (sUser.getMemo() != null) {
                    sql = sql + " AND memo =  '" + sUser.getMemo() + "'";
                }
                if (sUser.getIpmask() != null) {
                    sql = sql + " AND ipmask =  '" + sUser.getIpmask() + "'";
                }
                if (sUser.getOrderno() != null) {
                    sql = sql + " AND orderno =  '" + sUser.getOrderno() + "'";
                }
                if (sUser.getQuestion() != null) {
                    sql = sql + " AND question =  '" + sUser.getQuestion() + "'";
                }
                if (sUser.getAnswer() != null) {
                    sql = sql + " AND answer =  '" + sUser.getAnswer() + "'";
                }
                if (sUser.getOrgid() != null) {
                    sql = sql + " AND orgid =  '" + sUser.getOrgid() + "'";
                }
                if (sUser.getDepno() != null) {
                    sql = sql + " AND depno =  '" + sUser.getDepno() + "'";
                }
                if (sUser.getSessionId() != null) {
                    sql = sql + " AND session_id =  '" + sUser.getSessionId() + "'";
                }
                if (sUser.getRank() != null) {
                    sql = sql + " AND rank =  '" + sUser.getRank() + "'";
                }
                if (sUser.getParentactorno() != null) {
                    sql = sql + " AND parentactorno =  '" + sUser.getParentactorno() + "'";
                }
                if (sUser.getDeviceNo() != null) {
                    sql = sql + " AND device_no =  '" + sUser.getDeviceNo() + "'";
                }
                if (sUser.getMenuConfig() != null) {
                    sql = sql + " AND menu_config =  '" + sUser.getMenuConfig() + "'";
                }
                if (sUser.getIsPriorityShow() != null) {
                    sql = sql + " AND is_priority_show =  '" + sUser.getIsPriorityShow() + "'";
                }
                if (sUser.getIfTogetherWf() != null) {
                    sql = sql + " AND if_together_wf =  '" + sUser.getIfTogetherWf() + "'";
                }
                if (sUser.getOpModel() != null) {
                    sql = sql + " AND op_model =  '" + sUser.getOpModel() + "'";
                }
                if (sUser.getMobNum() != null) {
                    sql = sql + " AND mob_num =  '" + sUser.getMobNum() + "'";
                }
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            while (rs.next()) {
				SUser obj = new SUser();
				obj.setActorno(rs.getString("actorno"));
				obj.setEnname(rs.getString("enname"));
				obj.setActorname(rs.getString("actorname"));
				obj.setNickname(rs.getString("nickname"));
				obj.setState(rs.getString("state"));
				obj.setPassword(rs.getString("password"));
				obj.setStartdate(rs.getString("startdate"));
				obj.setPasswvalda(rs.getString("passwvalda"));
				obj.setFiredate(rs.getString("firedate"));
				obj.setBirthday(rs.getString("birthday"));
				obj.setTelnum(rs.getString("telnum"));
				obj.setIdcardno(rs.getString("idcardno"));
				obj.setAllowopersys(rs.getString("allowopersys"));
				obj.setLastlogdat(rs.getString("lastlogdat"));
				obj.setCreater(rs.getString("creater"));
				obj.setCreattime(rs.getString("creattime"));
				obj.setUsermail(rs.getString("usermail"));
				obj.setWrongpinnum(rs.getBigDecimal("wrongpinnum"));
				obj.setIsadmin(rs.getString("isadmin"));
				obj.setMemo(rs.getString("memo"));
				obj.setIpmask(rs.getString("ipmask"));
				obj.setOrderno(rs.getBigDecimal("orderno"));
				obj.setQuestion(rs.getString("question"));
				obj.setAnswer(rs.getString("answer"));
				obj.setOrgid(rs.getString("orgid"));
				obj.setDepno(rs.getString("depno"));
				obj.setSessionId(rs.getString("session_id"));
				obj.setRank(rs.getString("rank"));
				obj.setParentactorno(rs.getString("parentactorno"));
				obj.setDeviceNo(rs.getString("device_no"));
				obj.setIsPriorityShow(rs.getString("is_priority_show"));
				obj.setIfTogetherWf(rs.getString("if_together_wf"));
				obj.setOpModel(rs.getString("op_model"));
				obj.setMobNum(rs.getString("mob_num"));
                result.add(obj);
			}
        } catch (SQLException e) {
            throw new SQLException("update SUser is Wrong!" + e.getMessage());
        } finally {
            close(rs, null, ps);
        }
        return result;
	}

    /**
	 * 关闭资源
	 * @param theRs
	 * @param theStmt
	 * @param thePs
	 */
    protected void close(ResultSet theRs, Statement theStmt, PreparedStatement thePs) {
        try {
            if (theRs != null)
                theRs.close();
            if (theStmt != null)
                theStmt.close();
            if (thePs != null)
                thePs.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

}
